//https://leetcode.cn/problems/minimum-limit-of-balls-in-a-bag/submissions/565815555/

class Solution {
public:
    int minimumSize(vector<int>& v, int m) {
        int l = 1,
            r = *std::max_element(begin(v), end(v)),
            mid,
            ans = -1;
        auto f = [&](int x) {
            int k = 0;
            int sz = v.size();
            for (int i = 0; i < sz; i++)
                k += (v[i]-1)/x;
            return k <= m;
        };
        while (l <= r) {
            mid = (l+r)>>1;
            if (f(mid)) r = mid-1, ans = mid;
            else l = mid+1;
        }

        return ans;
    }
};